#!/usr/bin/env python
# -*- coding: utf-8 -*-

import json
import sys, os
from Shopping.core import db_handler

def load_user_info(user_id):
    '''
    返回用户所有信息
    :param user_id: 用户id
    :return:
    '''
    db_api = db_handler.db_handler()
    account_file = os.path.join(db_api, user_id+'.json')
    if os.path.isfile(account_file):
        with open(account_file, 'r', encoding='utf-8') as f:
            account_data = json.load(f)
            return account_data

def dump_user(user_data):
    '''
    更新用户的数据信息,并写入到数据库
    :param user_data: 用户所有的数据信息
    :return:
    '''
    db_api = db_handler.db_handler()
    account_file = os.path.join(db_api, user_data['id'])
    with open(account_file, 'w', encoding='utf-8') as f:
        account_data = json.dump(user_data, f)
    return True